home *** CD-ROM | disk | FTP | other *** search
/ Java for 3D & VRML Worlds / Java for 3d and VRML Worlds.iso / vs / browser / cpn11b1.exe / DATA.Z / origami.java < prev    next >
Text File  |  1996-09-25  |  3KB  |  143 lines

  1. /*-----------------------------------------------------------------------------
  2.  * Copyright(C) 1996 Sony Corporation. All rights reserved.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Sony Corporation;
  6.  * the contents of this file is not to be disclosed to third parties, copied
  7.  * or duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Sony Corporation.
  9.  *
  10.  * File:   origami.java
  11.  * Auther: sugino
  12.  *----------------------------------------------------------------------------*/
  13. import vrml.*;
  14. import vrml.node.*;
  15. import vrml.field.*;
  16.  
  17. public class origami extends Script {
  18.  
  19.     SFInt32     paperChild;
  20.     SFBool      timerOn    ;
  21.     SFRotation  birdRotation;
  22.  
  23.     SFTime      bgmStop  ;
  24.     SFTime      bgmStart  ;
  25.     SFTime      gusyaStop  ;
  26.     SFTime      gusyaStart  ;
  27.  
  28.     /* number of child  */
  29.     int max = 8;
  30.     /* current child no */
  31.     int current = 0;
  32.  
  33.     int xrollMax = 60;
  34.     int xroll = 0;
  35.  
  36.     int yrollMax = 60;
  37.     int yroll = 0;
  38.  
  39.     boolean rolling= false;
  40.  
  41.     final int rollingX = 1;
  42.     final int rollingY = 2;
  43.  
  44.     int rollmode = rollingX;
  45.  
  46.     float rotation[] = new float[4];
  47.  
  48.     float piV = (float)Math.PI/180.0f ;
  49.     float xaRad = (360.0f/(float)xrollMax);
  50.     float yaRad = (360.0f/(float)yrollMax);
  51.  
  52.  
  53.     public void initialize () {
  54.     paperChild = (SFInt32) getEventOut("paperChild");
  55.     timerOn    = (SFBool)  getEventOut("timerOn");
  56.     birdRotation = (SFRotation) getEventOut("birdRotation");
  57.  
  58.     bgmStop  = (SFTime) getEventOut("bgmStop");
  59.     bgmStart  = (SFTime) getEventOut("bgmStart");
  60.     gusyaStop  = (SFTime) getEventOut("gusyaStop");
  61.     gusyaStart  = (SFTime) getEventOut("gusyaStart");
  62.     }
  63.  
  64.     public void processEvent (Event e){
  65.     String name = e.getName();
  66.  
  67.     if(name.equals("clicked")){
  68.         clicked ((ConstSFBool)e.getValue(),e.getTimeStamp());
  69.     }
  70.     if(name.equals("roll")){
  71.         roll((ConstSFTime)e.getValue(), e.getTimeStamp());
  72.     }
  73.     }
  74.  
  75.     public void clicked (ConstSFBool press, double t) {
  76.         if(press.getValue()) return ;
  77.  
  78.     if(rolling) {
  79.         rolling=false;
  80.         bgmStop.setValue(t);
  81.     }
  82.     else {
  83.         rolling=true;
  84.             gusyaStart.setValue(t);
  85.         bgmStart.setValue(t);
  86.     }
  87.     timerOn.setValue(rolling);
  88.     nextChild(t);
  89.     }
  90.  
  91.     public void roll(ConstSFTime t, double now){
  92.  
  93.     rotation[0]=rotation[1]=rotation[2]=0.0f;
  94.     if(rollmode == rollingX){
  95.         if(xroll < xrollMax) {
  96.         xroll++;
  97.         }
  98.         else {
  99.         xroll = 0;
  100.         rollmode = rollingY;
  101.         }
  102.     }
  103.     else {
  104.         if(yroll < yrollMax) {
  105.         yroll++;
  106.         }
  107.         else {
  108.         yroll = 0;
  109.         nextChild(now);
  110.         rollmode = rollingX;
  111.         }
  112.     }    
  113.     if(rollmode == rollingX){
  114.         rotation[0]=1.0f;
  115.         rotation[3]= (piV*(xaRad*(float)xroll)) ;
  116.     }
  117.     else {
  118.         rotation[1]=1.0f;
  119.         rotation[3]= (piV*(yaRad*(float)yroll)) ;
  120.     }
  121.  
  122.     birdRotation.setValue(rotation);
  123.     }
  124.     void nextChild(double t){
  125.     gusyaStop.setValue(t - 3);    
  126.     gusyaStart.setValue(t);    
  127.     if(current < max-1) current++ ;
  128.     else {
  129.         current =0;
  130.         rolling = false;
  131.         timerOn.setValue(rolling);
  132.         bgmStop.setValue(t);
  133.     }
  134.     paperChild.setValue(current);
  135.     }    
  136. }
  137.  
  138.     
  139.  
  140.  
  141.  
  142.  
  143.